//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package weaver.interfaces.expense.action.gzc;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.util.ExpenseCompare;
import weaver.interfaces.util.ExpenseCompareUtil;
import weaver.interfaces.util.ExpenseInfoUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

public class YSKFWZLY_ExpenseAction extends BaseBean implements Action {
    public YSKFWZLY_ExpenseAction() {
    }

    public String execute(RequestInfo requestInfo) {
        try {
            String workflowid = requestInfo.getWorkflowid();
            String requestid = requestInfo.getRequestid();
            this.writeLog("进入YSKFWZLY_ExpenseAction-----------" + requestid);
            RecordSet rs = new RecordSet();
            rs.executeSql("select formid from workflow_base where id = " + workflowid);
            rs.next();
            String formid = rs.getString("formid");
            String formtable = "formtable_main_" + formid.replaceAll("-", "");
            ExpenseInfoUtil expenseInfoUtil = new ExpenseInfoUtil();
            String ccode = "";
            double amount = 0.0D;
            String cexpenseitemcode = "";
            String citemcode = "";
            String iyear = "";
            String iskt = "0";
            rs.execute("select a.id,b.ks,a.zcxm,a.je,b.sqrq,b.kth1,b.sf from " + formtable + "_dt1 a , " + formtable + " b where a.mainid=b.id and  b.requestid=" + requestid);

            String kth;
            while(rs.next()) {
                ccode = expenseInfoUtil.getKsbm(Util.null2String(rs.getString("ks")));
                amount = Util.getDoubleValue(rs.getString("je"), 0.0D);
                cexpenseitemcode = Util.null2String(rs.getString("zcxm"));
                kth = Util.null2String(rs.getString("kth1"));
                iyear = Util.null2String(rs.getString("sqrq")).substring(0, 4);
                String sfkt = Util.null2String(rs.getString("sf"));
                ExpenseCompareUtil expenseCompareUtil = new ExpenseCompare();
                if("0".equals(sfkt)) {
                    iskt = "1";
                    if(!expenseCompareUtil.compareExpense2(workflowid, cexpenseitemcode, kth, amount, iyear)) {
                        requestInfo.getRequestManager().setMessageid("1111111111");
                        requestInfo.getRequestManager().setMessagecontent("课题号:" + kth + " ,支出项目:" + expenseInfoUtil.getCItemName(cexpenseitemcode) + "的预算不足");
                        return "1";
                    }
                }

                if("1".equals(sfkt) && !expenseCompareUtil.compareExpense5(workflowid, ccode, cexpenseitemcode, amount, iyear)) {
                    requestInfo.getRequestManager().setMessageid("1111111111");
                    requestInfo.getRequestManager().setMessagecontent("科室:" + expenseInfoUtil.getCname(ccode) + ",支出项目:" + expenseInfoUtil.getCItemName(cexpenseitemcode) + "的预算不足");
                    return "1";
                }
            }

            rs.beforFirst();

            while(rs.next()) {
                ccode = expenseInfoUtil.getKsbm(Util.null2String(rs.getString("ks")));
                amount = Util.getDoubleValue(rs.getString("je"), 0.0D);
                cexpenseitemcode = Util.null2String(rs.getString("zcxm"));
                kth = Util.null2String(rs.getString("kth1"));
                iyear = Util.null2String(rs.getString("sqrq")).substring(0, 4);
                if(!expenseInfoUtil.subtractExpense(workflowid, ccode, cexpenseitemcode, citemcode, kth, amount, iyear, iskt)) {
                    requestInfo.getRequestManager().setMessageid("1111111111");
                    requestInfo.getRequestManager().setMessagecontent("预算更新失败");
                    return "1";
                }
            }

            return SUCCESS;
        } catch (Exception var18) {
            requestInfo.getRequestManager().setMessageid("1111111111");
            requestInfo.getRequestManager().setMessagecontent(var18.getMessage());
            return "1";
        }
    }
}
